import {Page} from '@/base/Page';
import {Benefits} from '@/base/model/Benefits';
// import {getBannersList, deleteBanners, PutBannerId} from '@/base/api/BannersApi';
import {isEmpty} from '@/base/util/Strings';
import {deepAssign} from "@/base/util/Objects";
import {PutSoftwareId} from "@/base/api/SoftwareApi";
// import {Banners} from "@/base/model/Banners";
import {deleteBenefits, getBenefitsList} from "@/base/api/BenefitApi";

// class Form {
//   // createBegin = '';
//   // createEnd = '';
//   benefitname = '';
//   benefitIcon = '';
//   // date = [];
// }

export class BenefitsBloc {
  // form = new Form();
  paged: Page<Benefits> = new Page<Benefits>([], 0, 1, 15, 0, []);
  loading = false;

  load(pageIndex: number, pageSize: number) {
    this.loading = true;
    return getBenefitsList({
      pageIndex,
      pageSize,
      sortDirection: 'DESC',
    }).then((res) => {
      this.paged = res.data;
      // console.log(res.data);
    }).finally(() => {
      this.loading = false;
    });
  }
  reset() {
    this.paged.pageIndex = 1;
    this.paged.pageSize = 15;
    this.load(this.paged.pageIndex, this.paged.pageSize);
  }
  removeItem(dateItem: Benefits) {
    this.loading = true;
    console.log(dateItem.benefitId);
    return deleteBenefits(dateItem.benefitId)
      .finally(() => {
        this.loading = false;
      });
  }
}
